﻿#If NETFX_CORE Then

#If FEATURE_OWN_MONO_GAME Then

Imports Microsoft.Xna.Framework
Imports Windows.UI.Core

Namespace Global.Runa.Common.MetroGame

    Public Class XamlGame(Of T As Game)

        Public Property Game() As Game

        Public Sub New()
            Me.Game = Activator.CreateInstance(Of T)()
        End Sub

        Public Sub New(ByVal g As T)
            Me.Game = g
        End Sub

        Public Function Create(ByVal launchParameters As String, ByVal window As CoreWindow, ByVal swapPanel As SwapChainBackgroundPanel) As T
            If (launchParameters Is Nothing) Then
                Throw New NullReferenceException("The launch parameters cannot be null!")
            End If
            If (window Is Nothing) Then
                Throw New NullReferenceException("The window cannot be null!")
            End If
            If (swapPanel Is Nothing) Then
                Throw New NullReferenceException("The swap chain panel cannot be null!")
            End If
            MetroGamePlatform.LaunchParameters = launchParameters
            MetroGameWindow.Instance.Initialize(window, swapPanel)
            If (Me.Game.graphicsDeviceManager Is Nothing) Then
                Throw New NullReferenceException("You must create the GraphicsDeviceManager in the Game constructor!")
            End If
            Me.Game.graphicsDeviceManager.SwapChainPanel = swapPanel
            Me.Game.Run(GameRunBehavior.Asynchronous)
            Return Game
        End Function

    End Class

End Namespace

#End If

#End If